<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
    <style>
        div{
            display:none;
        }
        .active{
            background:yellow;
        }
    </style>
    <script>
        window.onload=function(){
            var aInput=document.getElementsByTagName('input');
            var aDiv=document.getElementsByTagName('div'); 
            for(var i=0;i<aInput.length;i++){               
                aInput[i].index=i;                          
                aInput[i].onclick=function(){
                    for(var j=0;j<aInput.length;j++){      
                        aInput[j].className=''             

                    }
                    for(var i=0;i<aDiv.length;i++){        
                        aDiv[i].style.display='none'
                    }
                    aInput[this.index].className='active'  
                    aDiv[this.index].style.display='block' 
                }
            }
        }
    </script>
<body>
    <input type="button" id="div1" value="tab1" index="0" />
    <input type="button" value="tab2" index="1"/>
    <div style="display:block">显示tab1</div>
    <div>显示tab2</div>
</body>

</html>